# -*- coding: utf-8 -*-

from aeConn import dbHandle
from compound import Compound
from reaction import Reaction

import yaml

def subStructSearch(fingerprint):

	params = {}
	print fingerprint

	body = yaml.dump(fingerprint)

	resp = dbHandle.postAction('subStructSearch', body, params)

	data = yaml.load(resp)
	
	compounds = [Compound(key) for key in data]

	return compounds

def searchReactions(filters):

	body = "{filters: ["
	for f in filters:
		body += '{'
		body += f._dumpYAML().replace('\n', ',\n')
		body += '},\n'
	body += "]}"

	resp = dbHandle.postAction('filterReactions', body, {})

	if resp:
		data = yaml.load(resp)

		reactions = [Reaction(key) for key in data]

	else:
		reactions = []

	return reactions